#pragma once
#ifndef __SCRIPT__EDITOR__SOLUTION__ITEM__HH__
#define __SCRIPT__EDITOR__SOLUTION__ITEM__HH__

#include "ScriptEditorPrereqs.h"
#include <qtreewidget.h>
#include <LitFilePath.h>

namespace Lit
{
	namespace Editor
	{
		class ScriptSolutionItem
		{
		public:
			enum Flags
			{
				ItemNone = 0,
				ItemIsCompilable = 1 << 1,
				ItemIsRender = 1 << 2
			};
			typedef QTreeWidgetItem Node;
			typedef RefPtr<Node>	NodePtr;

			typedef ScriptEditorWidget	Widget;
			typedef RefPtr<Widget>		WidgetPtr;

		protected:
			NodePtr				mNode;
			WidgetPtr			mEditor;
			ScriptSolutionPtr	mSolution;
			size_t				mFlags;
		public:
			ScriptSolutionItem( ScriptSolutionPtr parent, size_t flags = ItemIsCompilable );
			ScriptSolutionItem( ScriptSolutionPtr parent, const NodePtr& node, const WidgetPtr& window, size_t flags = ItemIsCompilable );
			ScriptSolutionItem( const ScriptSolutionItem& rk );
			ScriptSolutionItem& operator=( const ScriptSolutionItem& rk );
			~ScriptSolutionItem( );
			
			bool				isEditorOpen() const;
			void				openEditor( );
			void				closeEditor( );

			void				setCurrent( );
			bool				isCurrent() const;

			size_t				getFlags() const;
			void				setFlags( size_t flags );
			bool				testFlag( Flags flag );
			bool				testFlags( size_t flags );

			bool				isModified( ) const;
			void				setModified( bool state );

			NodePtr&			getNode();
			const NodePtr&		getNode() const;

			WidgetPtr&			getEditor();
			const WidgetPtr&	getEditor() const;

			ScriptSolutionPtr&			getParent();
			const ScriptSolutionPtr&	getParent() const;

			void				save( );
			void				load( );

			void				setPath( const FilePath& path );
			FilePath			getPath() const;

			std::string			getDir() const;

			void				setName( const std::string& str );
			std::string			getName( bool ext = true ) const;

			void				setContent( const std::string &txt );
			std::string			getContent( ) const;

			bool operator == ( const ScriptSolutionItem& other ) const;
			bool operator != ( const ScriptSolutionItem& other ) const;

			operator bool() const;

			void destroy();

		};
	};
};

#endif